package co.fitstart.weapp.api.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.principal.PrincipalMessage;
import co.fitstart.weapp.api.dao.CoachMessageDao;
import co.fitstart.weapp.api.service.CoachMessageService;

/**
 * @ClassName: CoachMessageServiceImpl  
 * @author: cuteHU  
 * @date: 2018年12月3日
 */
@Service("coachMessageService")
public class CoachMessageServiceImpl implements CoachMessageService {
    
    @Dao
    private CoachMessageDao coachMessageDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CoachMessageService#list(co.fitstart.entity.principal.Principal, int, int)
     */
    public List<PrincipalMessage> list(Principal principal, int begin, int length) {
        return coachMessageDao.list(principal, begin, length);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CoachMessageService#load(java.lang.Long)
     */
    @Override
    public PrincipalMessage load(Long messageId) {
        return coachMessageDao.load(messageId);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CoachMessageService#isRead(java.lang.Long, boolean)
     */
    @Override
    public boolean isRead(Long messageId, boolean read) {
        PrincipalMessage principalMessage=coachMessageDao.load(messageId);
        if(principalMessage.isRead()==true) {
            return true;
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CoachMessageService#update(co.fitstart.entity.principal.PrincipalMessage)
     */
    @Override
    public void update(Long messageId) {
        PrincipalMessage principalMessage = genericDaoSupport.load(PrincipalMessage.class,messageId);
        principalMessage.read();
        genericDaoSupport.update(principalMessage);
    }

}
